﻿using JobManageCommon.Common;
using System;

namespace JobManageCommon.DiskPartition
{
    /// <summary>
    /// 获取当前盘符信息
    /// </summary>
    public class HardDiskPartition
    {
        /// <summary>
        /// 获取指定驱动器的空间总大小(单位 B)
        /// </summary>
        /// <param name="str_HardDiskName">只需输入代表驱动器的字母即可</param>
        /// <returns></returns>
        public static long GetHardDiskSpace(string str_HardDiskName)
        {
            try
            {
                long totalSize = new long();
                System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
                foreach (System.IO.DriveInfo drive in drives)
                {
                    if (drive.Name == str_HardDiskName.Substring(0,3))
                    {
                        totalSize = drive.TotalSize;
                    }
                }
                return totalSize;
            }
            catch (Exception ex)
            {
                ExportCommon.Exportfun(System.Environment.CurrentDirectory + "/error.log", ex.Message);
                return 0;
            }
        }

        /// <summary>
        /// 获取指定驱动器的剩余空间总大小(单位为B)
        /// </summary>
        /// <param name="str_HardDiskName">只需输入代表驱动器的字母即可</param>
        /// <returns></returns>
        public static long GetHardDiskFreeSpace(string str_HardDiskName)
        {
            try
            {
                long freeSpace = new long();
                System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
                foreach (System.IO.DriveInfo drive in drives)
                {
                    if (drive.Name == str_HardDiskName.Substring(0, 3))
                    {
                        freeSpace = drive.TotalFreeSpace;
                    }
                }
                return freeSpace;
            }
            catch (Exception)
            {
                return 0;
            }

        }
    }
}
